package com.cbd.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * @author BingBing
 * @desc  生产者消息发布失败返回回调类
 * @date 2024/11/14 15:42
 */
@Component
@Slf4j
public class MyMQReturnCallBack implements RabbitTemplate.ReturnsCallback {

    // 重写返回消息处理方法
    @Override
    public void returnedMessage(ReturnedMessage returnedMessage) {
        String message = new String(returnedMessage.getMessage().getBody());
        log.error("消息发布失败:{}", message);
    }
}
